package ssl;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author kastillo
 */
public class serssl {
// Este es un servidor que lee una línea por un socket
// SSL y la escribe por el mismoimport

   public static void setProgramInfo(String store) {
                System.setProperty("javax.net.ssl.keyStore",store);
                System.setProperty("javax.net.ssl.keyStorePassword","123456");
//                System.setProperty("javax.net.ssl.trustStore",store);
//                System.setProperty("javax.net.ssl.trustStorePassword","123456");
             }
    public static void main(String[] arstring) {
        setProgramInfo("store");
        int port = 2500;
        SSLServerSocket s;
        String cadena;

        try {
            System.out.println("Inicio del servidor");
            SSLServerSocketFactory sslSrvFact =
                    (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
            s = (SSLServerSocket) sslSrvFact.createServerSocket(port);
            SSLSocket c = (SSLSocket) s.accept();
            OutputStream os = c.getOutputStream();
            PrintWriter out = new PrintWriter(os, true);
            InputStream is = c.getInputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(is));

            cadena = in.readLine();
            System.out.println(cadena);
            out.println(cadena);
        } catch (IOException e) {
            System.out.println("Error de lectura: " + e.getMessage());
        }
    }
}

